if(condition) { statements ---------- } else { statements ---------- } next statements
import java.util.Scanner; class demo { public static void main(String args[]) { Scanner scan=new Scanner(System.in); System.out.print("Enter a Number:"); int a=scan.nextInt(); if(a%2==0) System.out.println("Number is EVEN"); else System.out.println("Number is ODD"); } }
Enter a Number 26 Number is Even
import java.util.Scanner; class demo { public static void main(String args[]) { Scanner stdin=new Scanner(System.in); System.out.print("Enter 3 angles:"); int a=stdin.nextInt(); int b=stdin.nextInt(); int c=stdin.nextInt(); if(a+b+c==180) System.out.println("Triangle can be formed"); else System.out.println("Triangle cannot be formed") } }
Enter 3 Angles 60 60 60
Tirangle Can be formed
import java.util.Scanner; class demo { public static void main(String args[]) { Scanner jin=new Scanner(System.in); System.out.print("Enter a Number:"); int a=jin.nextInt(); if(a>=10 && a<=99) System.out.println("It is a 2 digit Number"); else System.out.println("It is not a 2 digit Number"); } }
Enter a Number 26 It is a 2 digit Number
import java.util.Scanner; class demo { public static void main(String args[]) { Scanner stdin=new Scanner(System.in); System.out.print("Enter a Number:"); int a=stdin.nextInt(); if(a>=1000 && a<=9999) { System.out.println("It is a 4 digit Number"); int b=a%10; int c=a/10%10; int d=a/100%10; int e=a/1000; int s=b+c+d+e; System.out.println("sum of digits is "+s); } else System.out.println("It is not a 4 digit Number"); } }
Enter a Number 2656 It is a 4-digit number sum of number is 19
import java.util.Scanner; class demo { public static void main(String args[]) { Scanner stdin=new Scanner(System.in); System.out.print("Enter marks 5 subject:"); int a=stdin.nextInt(); int b=stdin.nextInt(); int c=stdin.nextInt(); int d=stdin.nextInt(); int e=stdin.nextInt(); if(a>=40 && b>=40 && c>=40 && d>=40 && e>=40) { System.out.println("\nPass"); int t=a+b+c+d+e; float p=t/100*500.0; System.out.println("Total Marks is"+t); System.out.println("Percentage is"+p); } else System.out.println("Fail"); } }
Enter marks of 5 subject 65 85 62 72 39 Student is Passed